/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VentanaImpresora.java
 *
 * Created on 26/08/2011, 19:12:09
 */
package tsb.UI.Ventanas;

import tsb.dominio.interfaces.*;
import java.util.ArrayList;

import tsb.dominio.dispositivos.hostfinal.Impresora;

/**
 *
 * @author Fede
 */
public class VentanaImpresora extends javax.swing.JFrame {
    
     private Impresora impresora;
    private ArrayList<InterfaceDeConeccion> listaInterfaces;

    /** Creates new form VentanaImpresora */
    public VentanaImpresora(String nombreAMostrar) {
        initComponents();
         
        listaInterfaces = new ArrayList<InterfaceDeConeccion>();
        
        tsb.gestores.GestorDeImpresora gestorImpresora = new tsb.gestores.GestorDeImpresora();
        Impresora impresora1=gestorImpresora.getImpresora("Impresora-1");
       
        this.setImpresora(impresora1);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panelImpresora = new tsb.UI.Paneles.PanelImpresora();
        panelBotones = new javax.swing.JPanel();
        btnCancelar = new javax.swing.JButton();
        btnAceptar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Impresora");

        panelBotones.setBackground(new java.awt.Color(255, 255, 255));

        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        btnAceptar.setText("Aceptar");
        btnAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAceptarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelBotonesLayout = new javax.swing.GroupLayout(panelBotones);
        panelBotones.setLayout(panelBotonesLayout);
        panelBotonesLayout.setHorizontalGroup(
            panelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelBotonesLayout.createSequentialGroup()
                .addContainerGap(263, Short.MAX_VALUE)
                .addComponent(btnAceptar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnCancelar)
                .addContainerGap())
        );
        panelBotonesLayout.setVerticalGroup(
            panelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelBotonesLayout.createSequentialGroup()
                .addContainerGap(13, Short.MAX_VALUE)
                .addGroup(panelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnCancelar)
                    .addComponent(btnAceptar))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panelImpresora, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(panelBotones, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(panelImpresora, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelBotones, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        this.panelImpresora.getInterfaz1();        // TODO add your handling code here:
}//GEN-LAST:event_btnCancelarActionPerformed

    private void btnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAceptarActionPerformed
        
        Impresora impresora= this.getImpresora();
        tsb.gestores.GestorDeImpresora gestorImpresora = new tsb.gestores.GestorDeImpresora();
        if(gestorImpresora.editarImpresora(impresora)) {
            System.out.println("se actualizo la pc");
        } else {
            System.out.println("No se actualizo");
        }
    }//GEN-LAST:event_btnAceptarActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAceptar;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JPanel panelBotones;
    private tsb.UI.Paneles.PanelImpresora panelImpresora;
    // End of variables declaration//GEN-END:variables

 public void setImpresora(Impresora impresora)
    {
        this.impresora=impresora;
        this.panelImpresora.setNombreAMostrar(impresora.getNombreAMostrar());
        this.panelImpresora.setEncendido(impresora.getEstado());
        if(impresora.getDHCP_Static()!=null)
        {
            this.panelImpresora.setAsignacionIP(impresora.getDHCP_Static());
        }
        this.panelImpresora.setGateway(impresora.getGateway());
        this.panelImpresora.setServidorDNS(impresora.getServidorDNS());
    }
    
    public Impresora getImpresora()
    {
        this.impresora.setNombreAMostrar(this.panelImpresora.getNombreAMostrar());
        this.impresora.setEstado(this.panelImpresora.getEncendido());
        this.impresora.setDHCP_Static(this.panelImpresora.getAsignacionIP());
        this.impresora.setGateway(this.panelImpresora.getServdorDNS());
        this.impresora.setGateway(this.panelImpresora.getGateway());
        this.impresora.setServidorDNS(this.panelImpresora.getServdorDNS());
        
        this.listaInterfaces.add(this.panelImpresora.getInterfaz1());
        
        this.impresora.setInterfaces(listaInterfaces);
        
        return impresora;
        
    }

}
